Completed
Push — master ( 809444...363a27 )
by Maxence
05:40 queued 02:26
created

nav.initElementsAddMemberNavigation   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var nav = {
38
39
	initNavigation: function () {
40
		this.initElementsAddMemberNavigation();
41
		this.initElementsLinkCircleNavigation();
42
		this.initElementsCircleNavigation();
43
44
		this.displayCirclesList('all');
45
	},
46
47
48
	initElementsAddMemberNavigation: function () {
49
50
		elements.addMember.hide();
51
		elements.addMember.on('input propertychange paste focus', function () {
52
			var search = $(this).val().trim();
53
			if (search === '') {
54
				elements.membersSearchResult.fadeOut(400);
55
				return;
56
			}
57
58
			actions.searchMembersRequest(search);
59
			if (elements.membersSearchResult.children().length === 0) {
60
				elements.membersSearchResult.fadeOut(400);
61
			} else {
62
				elements.membersSearchResult.fadeIn(400);
63
			}
64
		}).blur(function () {
65
			elements.membersSearchResult.fadeOut(400);
66
			nav.circlesActionReturn();
67
		});
68
	},
69
70
71
	initElementsLinkCircleNavigation: function () {
72
73
		elements.linkCircle.hide();
74
		elements.linkCircle.on('keydown', function (e) {
75
76
			if (e.keyCode !== 13) {
77
				return;
78
			}
79
80
			api.linkCircle(curr.circle, elements.linkCircle.val(), actions.linkCircleResult);
81
		}).blur(function () {
82
			nav.circlesActionReturn();
83
		});
84
	},
85
86
87
	initElementsCircleNavigation: function () {
88
89
		elements.joinCircle.hide();
90
		elements.joinCircle.on('click', function () {
91
			api.joinCircle(curr.circle, actions.joinCircleResult);
92
			nav.circlesActionReturn();
93
		});
94
95
		elements.leaveCircle.hide();
96
		elements.leaveCircle.on('click', function () {
97
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
98
			nav.circlesActionReturn();
99
		});
100
101
		elements.destroyCircle.on('click', function () {
102
			OC.dialogs.confirm(
103
				t('circles', 'Are you sure you want to delete this circle?'),
104
				t('circles', 'Please confirm'),
105
				function (e) {
106
					if (e === true) {
107
						api.destroyCircle(curr.circle, actions.destroyCircleResult);
108
					}
109
				});
110
		});
111
112
		elements.joinCircleAccept.on('click', function () {
113
			api.joinCircle(curr.circle, actions.joinCircleResult);
114
		});
115
116
		elements.joinCircleReject.on('click', function () {
117
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
118
		});
119
	},
120
121
122
	displayCirclesList: function (type) {
123
124
		curr.circlesType = type;
125
		curr.searchCircle = '';
126
		curr.searchUser = '';
127
128
		curr.circle = 0;
129
		curr.circleLevel = 0;
130
131
		elements.navigation.show('slide', 800);
132
		elements.emptyContent.show(800);
133
		elements.mainUI.fadeOut(800);
134
135
		elements.circlesSearch.val('');
136
		elements.addMember.val('');
137
		elements.linkCircle.val('');
138
139
		this.resetCirclesTypeSelection(type);
140
		elements.resetCirclesList();
141
		api.searchCircles(type, '', 0, actions.listCirclesResult);
142
	},
143
144
145
	resetCirclesTypeSelection: function (type) {
146
		elements.circlesList.children('div').removeClass('selected');
147
		elements.circlesList.children().each(function () {
148
			if ($(this).attr('circle-type') === type.toLowerCase()) {
149
				$(this).addClass('selected');
150
			}
151
		});
152
	},
153
154
155
	circlesActionReturn: function () {
156
		nav.displayCircleButtons(true);
157
		nav.displayAddMemberInput(false);
158
		nav.displayLinkCircleInput(false);
159
		nav.displayJoinCircleButton(false);
160
		nav.displayInviteCircleButtons(false);
161
	},
162
163
	joinCircleAction: function () {
164
		nav.displayCircleButtons(false);
165
		nav.displayAddMemberInput(false);
166
		nav.displayLinkCircleInput(false);
167
		nav.displayJoinCircleButton(true);
168
	},
169
170
	displayCircleButtons: function (display) {
171
		if (display) {
172
			elements.buttonCircleActionReturn.hide(200);
173
			elements.buttonCircleActions.delay(200).show(200);
174
		} else {
175
			elements.buttonCircleActions.hide(200);
176
			elements.buttonCircleActionReturn.delay(200).show(200);
177
		}
178
	},
179
180
	displayAddMemberInput: function (display) {
181
		if (display) {
182
			elements.addMember.val('');
183
			elements.addMember.delay(200).show(200);
184
		} else {
185
			elements.addMember.hide(200);
186
		}
187
	},
188
189
	displayLinkCircleInput: function (display) {
190
		if (display) {
191
			elements.linkCircle.val('');
192
			elements.linkCircle.delay(200).show(200);
193
		} else {
194
			elements.linkCircle.hide(200);
195
		}
196
	},
197
198
	displayInviteCircleButtons: function (display) {
199
		if (display) {
200
			elements.joinCircleAccept.show(200);
201
			elements.joinCircleReject.delay(200).show(200);
202
		} else {
203
			elements.joinCircleAccept.hide(200);
204
			elements.joinCircleReject.hide(200);
205
		}
206
	},
207
208
	displayJoinCircleButton: function (display) {
209
		if (display) {
210
			if (curr.circleStatus === 'Invited') {
211
				elements.joinCircle.hide(200);
212
				elements.leaveCircle.hide(200);
213
				nav.displayInviteCircleButtons(true);
214
215
			} else {
216
				nav.displayInviteCircleButtons(false);
217
218
				if (curr.circleLevel === 0 && curr.circleStatus !== 'Requesting') {
219
					elements.joinCircle.delay(200).show(200);
220
					elements.leaveCircle.hide(200);
221
					elements.joinCircleAccept.hide(200);
222
					elements.joinCircleReject.hide(200);
223
224
				}
225
				else {
226
					elements.leaveCircle.delay(200).show(200);
227
					elements.joinCircle.hide(200);
228
				}
229
			}
230
		} else {
231
			elements.joinCircle.hide(200);
232
			elements.leaveCircle.hide(200);
233
		}
234
	},
235
236
237
	/**
238
	 *
239
	 * @param display
240
	 */
241
	displayOptionsNewCircle: function (display) {
242
		if (display) {
243
			elements.newType.fadeIn(300);
244
			elements.newSubmit.fadeIn(500);
245
			elements.newTypeDefinition.fadeIn(700);
246
		}
247
		else {
248
			elements.newType.fadeOut(700);
249
			elements.newSubmit.fadeOut(500);
250
			elements.newTypeDefinition.fadeOut(300);
251
		}
252
	},
253
254
255
	displayMembers: function (members) {
256
257
		elements.remMember.fadeOut(300);
258
		elements.rightPanel.fadeOut(300);
259
260
		elements.mainUIMembers.emptyTable();
261
		if (members === null) {
262
			elements.mainUIMembers.hide(200);
263
			return;
264
		}
265
266
		elements.mainUIMembers.show(200);
267
		for (var i = 0; i < members.length; i++) {
268
			var tmpl = elements.generateTmplMember(members[i]);
269
			elements.mainUIMembers.append(tmpl);
270
		}
271
272
		for (i = 0; i < 10; i++) {
273
			if (curr.circleLevel < 9 && curr.circleLevel <= i) {
274
				$('.level-select option[value="' + i + '"]').attr('disabled', 'disabled');
275
			}
276
		}
277
278
279
		elements.mainUIMembers.children('tr.entry').each(function () {
280
281
				var userId = $(this).attr('member-id');
282
283
				//
284
				// level
285
				var level = $(this).attr('member-level');
286
				var levelSelect = $(this).find('.level-select');
287
				if (level === '0') {
288
					levelSelect.hide();
289
				}
290
				else {
291
					levelSelect.show(200).val(level);
292
				}
293
				levelSelect.on('change', function () {
294
					actions.changeMemberLevel(userId, $(this).val());
295
				});
296
297
				//
298
				// status
299
				var status = $(this).attr('member-status');
300
				var statusSelect = $(this).find('.status-select');
301
302
				statusSelect.on('change', function () {
303
					actions.changeMemberStatus(userId, $(this).val());
304
				});
305
				statusSelect.append($('<option>', {
306
					value: status,
307
					text: t('circles', status)
308
				})).val(status);
309
310
				if (curr.circleLevel <= $(this).attr('member-level')) {
311
					return;
312
				}
313
314
				if (status === 'Member' || status === 'Invited') {
315
					statusSelect.append($('<option>', {
316
						value: 'remove_member',
317
						text: t('circles', 'Kick this member')
318
					}));
319
				}
320
321
				if (status === 'Requesting') {
322
					statusSelect.append($('<option>', {
323
						value: 'accept_request',
324
						text: t('circles', 'Accept the request')
325
					}));
326
					statusSelect.append($('<option>', {
327
						value: 'dismiss_request',
328
						text: t('circles', 'Dismiss the request')
329
					}));
330
				}
331
332
			}
333
		)
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
334
	},
335
336
337
338
	displayCircleDetails: function (details) {
339
		elements.circlesDetails.children('#name').text(details.name);
340
		elements.circlesDetails.children('#type').text(t('circles', details.typeLongString));
341
342
		elements.buttonCircleActions.show(300);
343
		elements.addMember.hide(300);
344
	},
345
346
347
	displayMembersInteraction: function (details) {
348
		if (details.user.level < define.levelModerator) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
349
			elements.buttonAddMember.hide();
350
		} else {
351
			elements.buttonAddMember.show();
352
		}
353
354
		if (curr.allowed_federated === '0' || details.type === 'Personal' ||
355
			details.user.level < define.levelAdmin) {
356
			elements.buttonLinkCircle.hide();
357
		} else {
358
			elements.buttonLinkCircle.show();
359
		}
360
361
		elements.joinCircleInteraction.hide();
362
		this.displayNonMemberInteraction(details);
363
364
		if (details.user.level === define.levelOwner) {
365
			elements.destroyCircle.show();
366
			elements.buttonCircleSettings.show();
367
			elements.buttonJoinCircle.hide();
368
			return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
369
		}
370
371
	},
372
373
374
	displayNonMemberInteraction: function (details) {
375
		elements.joinCircleAccept.hide();
376
		elements.joinCircleReject.hide();
377
		elements.joinCircleRequest.hide();
378
		elements.joinCircleInvite.hide();
379
		elements.buttonCircleSettings.hide();
380
		elements.destroyCircle.hide();
381
382
		if (details.user.status === 'Requesting') {
383
			elements.joinCircleRequest.show();
384
			return;
385
		}
386
387
		if (details.user.level > 0) {
388
			return;
389
		}
390
391
		setTimeout(function () {
392
			nav.joinCircleAction();
393
		}, 200);
394
	}
395
396
};
397
398